package com.hc.service.impl;

import com.hc.entity.Manager;
import java.util.List;
import com.github.pagehelper.PageHelper;
import com.hc.service.ManagerService;
import com.hc.dao.ManagerDao;
import com.hc.utils.PageBean;
import com.hc.utils.PageParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ManagerServiceImpl implements ManagerService {

    @Autowired
    private ManagerDao managerDao;

    @Override
    public int addManager(Manager manager){
        int res = managerDao.insertManager(manager);
        return res;
    }

    @Override
    public int addManagerSelective(Manager manager){
        int res = managerDao.insertManagerSelective(manager);
        return res;
    }

	@Override
    public int batchAddManager(List<Manager> managerList){
		int res = managerDao.batchInsertManager(managerList);
		return res;
	}

    @Override
    public int deleteManagerById(Integer id){
        int res = managerDao.deleteManagerById(id);
        return res;
    }
    
 	@Override
	public int deleteManagerByCondition(Manager manager){
	 	int res = managerDao.deleteManagerByCondition(manager);
        return res;
	}
	
	@Override
	public int batchDeleteManagerByIdList(List<Integer> idList){
		int res = managerDao.batchDeleteManagerByIdList(idList);
        return res;
	}
	
    @Override
    public int updateManager(Manager manager){
        int res = managerDao.updateManager(manager);
        return res;
    }

    @Override
    public int updateManagerSelective(Manager manager){
        int res = managerDao.updateManagerSelective(manager);
        return res;
    }

    @Override
    public long getCount(){
        long res = managerDao.selectCount();
        return res;
    }

    @Override
    public long getCountByCondition(Manager manager){
        long res = managerDao.selectCountByCondition(manager);
        return res;
    }

    @Override
    public Manager getManagerById(Integer id){
        Manager res = managerDao.selectManagerById(id);
        return res;
    }

    @Override
    public List<Manager> getAllManager(){
        List<Manager> res = managerDao.selectAllManager();
        return res;
    }

	@Override
	public 	List<Manager> getManagerByCondition(Manager manager){
		List<Manager> res = managerDao.selectManagerByCondition(manager);
		return res;
	}
	
    @Override
    public PageBean<Manager> getManagerWithPagination(PageParam pageParam){
        long count = managerDao.selectCount();
        PageBean<Manager> pageBean = new PageBean<>(pageParam, (int)count);
        pageBean.setPageNum(pageParam.getPage());
        PageHelper.startPage(pageParam.getPage(),pageParam.getRows());
        List<Manager> data = managerDao.selectAllManager();
        pageBean.setRecords(data);
        return pageBean;
    }

	@Override
	public PageBean<Manager> getManagerWithPaginationByCondition(PageParam pageParam, Manager manager){
        long count = managerDao.selectCountByCondition(manager);
        PageBean<Manager> pageBean = new PageBean<>(pageParam, (int)count);
        pageBean.setPageNum(pageParam.getPage());
        PageHelper.startPage(pageParam.getPage(),pageParam.getRows());
		List<Manager> data = managerDao.selectManagerByCondition(manager);
		pageBean.setRecords(data);
        return pageBean;
	}

    //////////////////////////// 外键相关 /////////////////////////////////////
    @Override
    public List<Manager> getManagerByRole(Integer role){
        List<Manager> res = managerDao.selectManagerByRole(role);
        return res;
    }

}